package game.view;

import game.ClassicMode;
import game.Game;
import game.TimeAttackMode;

import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JPanel;

/**
 * Selcet mode panel.
 * @author Natchanon Hongladaromp
 *
 */
public class SelectModeUI extends JPanel
{
	private Game game;
	private JButton button1;
	private JButton button2;

	/**
	 * Construct for this panel.
	 * @param game
	 */
	public SelectModeUI(Game game)
	{
		this.game = game;
		initsComponents();
	}

	/**
	 * Initial components.
	 */
	private void initsComponents()
	{
		setLayout(new GridBagLayout());
		GridBagConstraints c = new GridBagConstraints();
		
		
		button1 = new JButton("Classic Mode");
		button1.setEnabled(false);
		button2 = new JButton("Time Attack Mode");
		
		button1.addActionListener(new ActionListener()
		{

			@Override
			public void actionPerformed(ActionEvent e)
			{
				game.setMode(new ClassicMode(game,5));
				button1.setEnabled(false);
				button2.setEnabled(true);
			}

		});

		button2.addActionListener(new ActionListener()
		{

			@Override
			public void actionPerformed(ActionEvent e)
			{
				game.setMode(new TimeAttackMode(game,60));
				button1.setEnabled(true);
				button2.setEnabled(false);
			}

		});
		
		c.fill = GridBagConstraints.HORIZONTAL;
		c.ipadx = 30;
		c.ipady = 20;
		c.gridx = 0;
		c.gridy = 0;
		add(button1,c);
		c.gridy = 1;
		add(button2,c);
	}

	/**
	 * turns off.
	 */
	public void off()
	{
		button1.setEnabled(false);
		button2.setEnabled(false);
	}
	
	/**
	 * turns on.
	 */
	public void on()
	{
		if(game.getMode().toString().equals("Classic Mode"))
			button2.setEnabled(true);
		else
			button1.setEnabled(true);
	}
}
